<%@page import="entities.Airport"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>List</title>


<SCRIPT src="js/jquery.min.js" type="text/javascript"></SCRIPT>
<SCRIPT src="js/moment.js" type="text/javascript"></SCRIPT>
<SCRIPT src="js/bootstrap-datetimepicker.js" type="text/javascript"></SCRIPT>
<SCRIPT src="js/bootstrap-datetimepicker.ru.js" type="text/javascript"></SCRIPT>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css">
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/moment.js"></script>
<script src="js/bootstrap3-typeahead.js"></script>


<!-- my style -->
<link href="css/dopstyle.css" rel="stylesheet">

<%
	String from = new String(request.getParameter("from").getBytes("ISO-8859-1"),"UTF-8");
	String where = new String(request.getParameter("where").getBytes("ISO-8859-1"),"UTF-8");
	String when = new String(request.getParameter("when").getBytes("ISO-8859-1"),"UTF-8");
	String fromAirport="";
	String whereAirport="";
	if(request.getParameter("fromAirport")!=null && request.getParameter("whereAirport")!=null )
	{
	    fromAirport = new String(request.getParameter("fromAirport").getBytes("ISO-8859-1"),"UTF-8");
	    whereAirport = new String(request.getParameter("whereAirport").getBytes("ISO-8859-1"),"UTF-8");	
	}
%>

<!-- копипаст старт -->
<%@page import="java.util.ArrayList"%>
<%@page import="javax.ejb.EJB"%>
<%@page import="specifications.CitySpecification"%>
<%@page import="specifications.AirportSpecification"%>
<%@page import="specifications.FlightSpecification"%>
<%@page import="ejb.CityRepositoryBean"%>
<%@page import="ejb.AirportRepositoryBean"%>
<%@page import="ejb.FlightRepositoryBean;"%>

<jsp:useBean id="FlightRepositoryBean" class="ejb.FlightRepositoryBean" />
<jsp:useBean id="CityRepositoryBean" class="ejb.CityRepositoryBean" />
<jsp:useBean id="AirportRepositoryBean"
	class="ejb.AirportRepositoryBean" />


<%
	ArrayList<entities.Flight> 	flights = new ArrayList<entities.Flight> ();
	if(request.getParameter("whereAirport")==null && request.getParameter("fromAirport")== null)
		{
	flights = FlightRepositoryBean.getSpecifiedFlights(from,where,when);
		}
	else
	{
		if(request.getParameter("whereAirport")!="" &&request.getParameter("fromAirport")!="")
		{
			flights = FlightRepositoryBean.getSpecifiedFlightsbyAirports(when,fromAirport,whereAirport);
		}
		else 
		{
			flights = FlightRepositoryBean.getSpecifiedFlights(from,where,when);
		}
	}

	ArrayList<entities.Airport> airportsDep = AirportRepositoryBean.getSpecifiedAirports(from);
	ArrayList<entities.Airport> airportsArr = AirportRepositoryBean.getSpecifiedAirports(where);
%>
<!-- копипаст энд -->

</head>
<body class="bg">


	<script>
		$(function() {
			$('#date').datetimepicker({
				language : 'ru',
				pickTime : false
			});
		});
	</script>


	<div class="container">
	
	
	<div class="header">
        <ul class="nav nav-pills pull-right">
          <%@ include file="LoginForm.jsp" %>
        </ul>
        <h3 class="text-muted"> </h3>
      </div>
	
		<div class="row">
			
			<div class="col-md-12 top-menu">

				<h1 class="text-city  text-center">
					<strong><%=from%></strong> —— ✈ ——<strong> <%=where%>
					</strong>
				</h1>
				<br> <br>
				<!-- -->
			</div>

			<div class="col-md-2  left-sidebar">
				<div class="well">
					<form class="form" method="Get"
						action="/NCProjectWeb/FlightsList.jsp" role="form">
						<INPUT TYPE="HIDDEN" NAME="from" VALUE=<%=from%>>
						 <INPUT
							TYPE="HIDDEN" NAME="where" VALUE=<%=where%>> 
						<!--аэропорт отбытия-->
						<div class="form-group">
							<label class="control-label">Аэропорт отбытия</label>
							<div>
								<select class="form-control select-sm" id="fromAirport"
									name="fromAirport">
									<%
										for (int i = 0; i < airportsDep.size(); i++) {
									%>
									<option><%=airportsDep.get(i).getAirportName()%></option>

									<%
										}
									%>
								</select>
							</div>
						</div>
						<!--аэропорт прибытия-->
						<div class="form-group">
							<label class="control-label">Аэропорт прибытия</label>
							<div>
								<select class="form-control select-sm" id="whereAirport"
									name="whereAirport">
									<%
										for (int i = 0; i < airportsArr.size(); i++) {
									%>
									<option><%=airportsArr.get(i).getAirportName()%></option>

									<%
										}
									%>
								</select>
							</div>
						</div>
						<!--Когда-->
						<div class="form-group">
							<label class="control-label">Когда</label>
							<div class="input-group date" id="date">
								<INPUT class="form-control input-sm" name="when" type="text"
									value="<%=when%>"> <SPAN class="input-group-addon">
									<SPAN class="glyphicon glyphicon-calendar"></SPAN>
								</SPAN>
							</div>
						</DIV>




						<button class="btn btn-primary">Найти</button>


					</form>
				</div>
			</div>


			<div class="col-md-10 content well well-lg">
				<table class="table table-striped">
					<thead>
						<tr>
							<th>Номер рейса</th>
							<th>Дата вылета</th>
							<th>Дата прилета</th>
							<th>Аэропорт вылета</th>
							<th>Аэропорт прилета</th>
							<th>Компания</th>
							<th>Тип самолета</th>
							<th>Стоимость эконом класс</th>
							<th>Стоимость бизнес класс</th>
							<th>Стоимость первый класс</th>
							<th>Доступно билетов - эконом класс</th>
							<th>Доступно билетов - бизнес класс</th>
							<th>Доступно билетов - первый класс</th>
						</tr>
					</thead>
					<tbody>


						<%
							for (int i = 0; i < flights.size(); i++) {
						%>
						<tr>
							<td><%=flights.get(i).getFlightNo()%></td>
							<td><%=flights.get(i).getDepartureTime()%></td>
							<td><%=flights.get(i).getArriveTime()%></td>
							<td><%=flights.get(i).getDepartureAirport().getAirportName()%></td>
							<td><%=flights.get(i).getArriveAirport().getAirportName()%></td>
							<td><%=flights.get(i).getFlightAirline().getAirlineName()%></td>
							<td><%=flights.get(i).getFlightAircraft().getAircraftType()%></td>
							<td><%=flights.get(i).getPriceEC()%></td>
							<td><%=flights.get(i).getPriceBC()%></td>
							<td><%=flights.get(i).getPriceFC()%></td>
							<td><%=flights.get(i).getAvEC()%></td>
							<td><%=flights.get(i).getAvBC()%></td>
							<td><%=flights.get(i).getAvFC()%></td>
							
							<td><a href="/NCProjectWeb/CheckLoginBeforeBy?id=<%=flights.get(i).getFlightNo()%>"><span class="glyphicon glyphicon-shopping-cart"></span></a>
							</td>
							<!-- <td><button type="button" class="btn btn-primary btn-sm">Купить</button></td>-->
						</tr>
						<%
						}
						%>

					</tbody>
				</table>
			</div>
		</div>
	</div>
	<!-- /container -->

	<!-- footer -->
	<div id="footer">
		<div class="container">
			<p class="text-muted">ХодорХодорХодорХодор 2014 (с) Женя</p>
		</div>
	</div>



</body>
</html>